package com.useeinfo.oa.modules.repair.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.repair.enums.RepairOrderLogOperationEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/12 13:46
 * @Description:
 */
@Entity
@Table(name = "repair_order_log")
public class RepairOrderLog extends SuperClassEntity<RepairOrderLog> {

    @ManyToOne
    @JoinColumn(name = "user_id")
    private SystemUser systemUser;

    private String userName;

    /**
     * 操作详情
     */
    private String detail;

    /**
     * 备注
     */
    private String remark;



    /**
     * 工单状态
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "repair_order_operation")
    private RepairOrderLogOperationEnum repairOrderLogOperationEnum;

    @ManyToOne
    @JoinColumn(name = "repair_order_id")
    private RepairOrder repairOrder;

    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public RepairOrderLogOperationEnum getRepairOrderLogOperationEnum() {
        return repairOrderLogOperationEnum;
    }

    public void setRepairOrderLogOperationEnum(RepairOrderLogOperationEnum repairOrderLogOperationEnum) {
        this.repairOrderLogOperationEnum = repairOrderLogOperationEnum;
    }

    public RepairOrder getRepairOrder() {
        return repairOrder;
    }

    public void setRepairOrder(RepairOrder repairOrder) {
        this.repairOrder = repairOrder;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }


    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("userName", StringConverters.null2String(getUserName()));
        jsonObject.put("operation", getRepairOrderLogOperationEnum().getName());
        jsonObject.put("detail", StringConverters.null2String(getDetail()));
        jsonObject.put("returnReason",StringConverters.null2String(getRemark()));
        return jsonObject;
    }
}
